package com.ruoyi.rocky.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.rocky.domain.PcExamine;
import com.ruoyi.rocky.domain.PcStore;
import com.ruoyi.rocky.domain.PcStoreJoin;
import com.ruoyi.rocky.service.PcStoreService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Slf4j
@Validated
@RestController
@RequestMapping("/pcStore")
@AllArgsConstructor
@Api(tags = "门店管理")
public class PcStoreController extends BaseController {

    @Autowired
    private PcStoreService pcStoreService;

    /**
     * 查询店铺列表
     */
    @ApiOperation(value = "查询店铺列表")
    @GetMapping("/list")
    public TableDataInfo list(PcStore pcStore)
    {
        startPage();
        List<PcStore> list = pcStoreService.selectPcStoreList(pcStore);
        return getDataTable(list);
    }

//    /**
//     * 导出店铺列表
//     */
//    @ApiOperation(value = "导出店铺列表")
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, PcStore pcStore)
//    {
//        List<PcStore> list = pcStoreService.selectPcStoreList(pcStore);
//        ExcelUtil<PcStore> util = new ExcelUtil<PcStore>(PcStore.class);
//        util.exportExcel(response, list, "店铺数据");
//    }

    /**
     * 获取店铺详细信息
     */
    @ApiOperation(value = "获取店铺详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(pcStoreService.selectPcStoreById(id));
    }

    /**
     * 申请店铺
     * @param storeJoin
     * @return
     */
    @ApiOperation(value = "申请店铺")
    @PostMapping(value = "/applyStore")
    public R applyStore(@Validated @RequestBody PcStoreJoin storeJoin) {
        return pcStoreService.applyStore(storeJoin);
    }

    /**
     * 店铺审核
     * @param dto
     * @return
     */
    @ApiOperation(value = "店铺审核")
    @PostMapping(value = "/examineStore")
    public R examineStore(@RequestBody PcExamine dto) {
        return pcStoreService.examineStore(dto);
    }

    /**
     * 修改店铺
     */
    @ApiOperation(value = "修改店铺")
    @PutMapping("/edit")
    public R edit(@RequestBody PcStore pcStore)
    {
        return R.ok(pcStoreService.updatePcStore(pcStore));
    }

    /**
     * 删除店铺
     */
    @ApiOperation(value = "删除店铺")
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable Long id)
    {
        return R.ok(pcStoreService.deletePcStoreById(id));
    }

}
